package com.zzh.structuredeployment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-11-14
 * @desc
 */
public class Algorithm {


    /**
     * 判断一个数字是不是素数
     *
     * @param number
     * @return
     */
    public boolean isPrimeNumber(int number) {
        if (number <= 2) {
            return false;
        }
        int halfNumber = number / 2;
        for (int i = 2; i < halfNumber; i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断是不是回文数
     *
     * @param number
     * @return
     */
    public boolean isPalindrome(int number) {
        if (number < 0) {
            throw new IllegalArgumentException("不能传入 小于零的数");
        }
        if (number < 10) {
            return true;
        }
        char[] numberChar = String.valueOf(number).toCharArray();

        for (int i = 0; i < numberChar.length / 2; i++) {
            if (numberChar[i] != numberChar[numberChar.length - 1 - i]) {
                return false;
            }
        }
        return true;
    }




}
